package com.cqs.example.websocket.h5;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


/**
 * 实现接口来配置Websocket请求的路径和拦截器
 *
 * @author lixiaowen
 * @date 2020/07/09
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //handler是webSocket的核心，配置入口
        registry.addHandler(new WebSocketHandler(), "/ws/msg/{ID}").setAllowedOrigins("*").addInterceptors(new WebSocketInterceptor());

    }


//    /**
//     * Spring boot自动加载的
//     * 不加这个Bean会跑错
//     *
//     * 目前不能从 不依赖TaskScheduler的角度解决该问题
//     * @return
//     */
//    @Bean
//    public TaskScheduler defaultSockJsTaskScheduler() {
//        ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
//        threadPoolScheduler.setThreadNamePrefix("SockJS-");
//        threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
//        threadPoolScheduler.setRemoveOnCancelPolicy(true);
//        return threadPoolScheduler;
//    }


}